<?php

class OrderAction extends SiteBaseAction
{
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * 订单列表
     */
    public function index()
    {
        //登录用户信息
        $user = Session('site');
        $user_id = $user['user_id'];

        //获取已经投放的广告
        $ad_putRelationship = M("putrelationship");
        $adInfo = $ad_putRelationship->where(array('site_user_id'=>$user_id))
            ->order('rel_id desc')
            ->field('advertising_id, advertising_name')
            ->select();

        //获取所有网站
        $site = M('site');
        $siteInfo = $site->where(array('user_id'=>$user_id))
            ->order('site_id desc')
            ->field('site_id, site_name')
            ->select();

        $isSelect = intval(I('isSelect'));

        if ($isSelect) {
            //广告ID
            $advertising_id = intval(I('advertising_id'));

            //网站ID
            $site_id = intval(I('site_id'));

            //分页每页的条数
            $perPage = $this->getPerPage();

            //查询条件
            $where = array();
            $where['advertising_id'] = $advertising_id;
            $where['site_id'] = $site_id;

            $currPage = intval($_GET['p']);
            $currPage < 1 && $currPage = 1;

            $ad_order = M("order");

            $itemCount = $ad_order->where($where)->count();
            $data = $ad_order->where($where)->order('order_id desc')->limit(($currPage-1)*$perPage, $perPage)->select();

            $itemPerPage = $perPage;
            $pageUrl = $this->baseUrl . '/Medium/Order/index';
            $paramQuery = array('advertising_id'=>$advertising_id, 'site_id'=>$site_id, 'isSelect'=>$isSelect);
            $paginator = new Paginator($currPage, $itemCount, $itemPerPage, $pageUrl, $paramQuery);

            $page = $paginator->getHtml(1);

        }

        $this->assign('baseUrl', $this->baseUrl);
        $this->assign('adInfo', $adInfo);
        $this->assign('siteInfo', $siteInfo);
        $this->assign('data', $data);
        $this->assign('page', $page);
        $this->assign('advertising_id', $advertising_id);
        $this->assign('site_id', $site_id);

        $this->display();
    }

}


?>